package view;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ressources.Constant;



//JPanel pour la section joueurs
class PlayersPanel extends JPanel{
    private PlayerPanel[] playersPanels = new PlayerPanel[6];
	public PlayersPanel(){
		this.setPreferredSize(new Dimension(500,350));
		this.setBorder(BorderFactory.createLineBorder (Color.gray, 1));
		this.setBackground(Color.white);


		this.setLayout(new GridLayout(7,1));
		JPanel pj = new JPanel(); 
		pj.setBackground(Color.white);
		JLabel lPlayer = new JLabel("   Joueurs");
		lPlayer.setFont(NewGameDialog.font);
		pj.add(lPlayer);
		this.add(pj);

		
		for(int i=0;i<Constant.NB_PLAYER_MAX;i++){
			playersPanels[i] = new PlayerPanel(Constant.getPawnColor(i),i+1);
			this.add(playersPanels[i]);
		}

	}
	
	public String[] getPlayers(){
		String players[] = new String[playersPanels.length];
		for(int i=0; i< playersPanels.length ; i++){
			players[i] = playersPanels[i].getName();
		}
		return players;
	}
}
//JPanel pour la section extensions
class ExtensionsPanel extends JPanel{

	public ExtensionsPanel(){

		this.setPreferredSize(new Dimension(500,140));
		this.setBorder(BorderFactory.createLineBorder (Color.gray, 1));
		this.setBackground(Color.white);
		this.setLayout(new GridLayout(3,1));

		JPanel pj = new JPanel(); 
		pj.setBackground(Color.white);
		JLabel lExtensions = new JLabel("Extensions");
		lExtensions.setFont(NewGameDialog.font);
		pj.add(lExtensions);
		this.add(pj);

		JPanel checkBtnExt = new JPanel();
		checkBtnExt.setLayout(new GridLayout(2,2));

		Font font = new Font("Verdana",Font.BOLD, 12);
		JCheckBox ext1 = new JCheckBox("La riviere");
		ext1.setFont(font);
		ext1.setBackground(Color.white);
		JCheckBox ext2 = new JCheckBox("Marchands et batisseurs");
		ext2.setFont(font);
		ext2.setBackground(Color.white);
		JCheckBox ext3 = new JCheckBox("Maires et cloitres");
		ext3.setFont(font);
		ext3.setBackground(Color.white);
		JCheckBox ext4 = new JCheckBox("Roi et Voleur");
		ext4.setFont(font);
		ext4.setBackground(Color.white);
		checkBtnExt.add(ext1);
		checkBtnExt.add(ext2);
		checkBtnExt.add(ext3);
		checkBtnExt.add(ext4);

		this.add(checkBtnExt);



	}
}

//JPanel pour la section boutons
class ButtonsPanel extends JPanel{
	public JButton play;
	public JButton cancel; 
	public ButtonsPanel(){
		this.setPreferredSize(new Dimension(500,50));
		this.setBorder(BorderFactory.createLineBorder (Color.gray, 1));
		this.setBackground(Color.white);
		Font fontB = new Font("Verdana",Font.BOLD, 12);
		play = new JButton(" Jouer ");
		play.setFont(fontB);
		cancel = new JButton(" Annuler ");
		cancel.setFont(fontB);
		this.add(play);
		this.add(cancel);
	}
	
	
}
public class NewGameDialog extends JDialog{
	public static Font font = new Font("Verdana",Font.BOLD, 16);
	public PlayersPanel pPlayers ;
	public ButtonsPanel pBtn ;
	public MainWindow mainWindow;
	public NewGameDialog(MainWindow main){
		this.mainWindow = main;
		this.setTitle("Nouvelle partie");
		this.setSize(550,600);
		this.setLocationRelativeTo(null);
		this.setModal(true);
		this.setResizable(false);

		Container c = this.getContentPane();

		pPlayers = new PlayersPanel(); 
		ExtensionsPanel pExtensions = new ExtensionsPanel();
		pBtn = new ButtonsPanel();

		c.setLayout(new FlowLayout());
		c.add(pPlayers);
		c.add(pExtensions);
		c.add(pBtn);
	}
	
	public JButton getPlayButton(){
		return this.pBtn.play;
	}
	public JButton getCancelButton(){
		return this.pBtn.cancel;
	}
	public String[] getNamesPlayer(){
		return this.pPlayers.getPlayers();
	}
	public void setActifPlayersPanel(ActifPlayersPanel panel){
		this.mainWindow.replaceActifPlayersPanel(panel);
	}

}
